<template>
  <div class="item" @click="handleItem">
    <img :src="props.data.picture" alt="">
    <div class="info">
      <h3> {{ props.data.title }}</h3>
      <span class="tip">¥{{ props.data.price }}</span>
    </div>
    <div class="seller">
      <img :src="props.data.seller.avatar" alt="">
      <div class="seller-info">
        <h3> {{ props.data.seller.name }}</h3>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const props = defineProps({
  data: {
    type: Object,
    required: true,
  }
});
const handleItem = () => {
  router.push(`/detail/${props.data.id}`)
}

</script>

<style lang="less" scoped>
.item {
  margin-top: 8px;
  box-sizing: border-box;
  padding: 10px;
  width: 252px;
  height: 348px;
  border-radius: 10px;
  border: 1px solid transparent;
  transition: all 0.5s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;

  &:hover {
    border: 1px solid #f3f3f3;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  }

  img {
    width: 244px;
    height: 244px;
    border-radius: 10px;
    margin-bottom: 10px;
    object-fit: cover;
    object-position: center;
  }

  .info {
    box-sizing: border-box;
    padding: 0 18px;
    width: 100%;
    font-size: 14px;
    font-weight: 500;

    h3 {
      font-size: 16px;
      font-weight: 600;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    span {
      display: block;
      color: red;
      font-size: large;
      font-weight: 600;
      height: 18px;
      border-radius: 5px;
      margin-top: 8px;
    }
  }

  .seller {
    margin-top: 4px;
    width: 100%;
    box-sizing: border-box;
    padding: 0 18px;
    display: flex;

    img {
      border-radius: 50%;
      width: 25px;
      height: 25px;
    }

    .seller-info {
      margin-left: 8px;
      height: 25px;
      line-height: 25px;
    }
  }
}
</style>
